04. CODE: Building, Running, and Testing
Building, Running, and Testing
## Compiling and Running
Compiling
Compiling your project code can be done from the terminal workspace or from the virtual workspace desktop, but GPU must be enabled. If using the virtual desktop, you will want to use a terminal from within VS Code, as the correct compiler options have been set up in the VS Code preferences. See the video below for a walkthrough of how to do this.
To compile the code, make a build
directory and then cd
into that directory. From the build
directory, you can then run the following commands to compile:
cmake ..
make
Running
Once the build is complete, the executable binary files will be in the bin
folder of the project, and the project will be ready to run. Running the project must be done from the workspace desktop in order for you to be able to see the mapped output, so be sure to click on the "Desktop" button in your workspace to open a virtual desktop window:
In the workspace desktop, you can open Visual Studio Code and a terminal within Visual Studio. In the terminal, navigate to the build folder. From the build
directory, you can run the compiled executable with map data using the following command:
../bin/CppND-Route-Planning-Project -f ../map.osm
For a video walkthrough of all of these steps from a fresh project in the workspace desktop, see the video below. Be sure to expand the video to full screen to be able to see terminal commands.
Build And Run
Try It Yourself
Now that you've seen how to compile and run the project, use the workspace below to do this yourself.
Workspace
This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.
Workspace Information:
- Default file path:
- Workspace type: react
- Opened files (when workspace is loaded): n/a
-
userCode:
export CXX=g++-7
export CXXFLAGS=-std=c++17
cmake_tests() {
/usr/local/bin/cmake -DTESTING="RouteModel" "$1"
}
export -f cmake_tests
## Testing
To ensure that your code is on the right track, some exercises will have unit tests.
IMPORTANT: In order to use the tests, your project code must be compiled using the classroom terminal and not the desktop Visual Studio. The classroom terminal has a bash script that applies the appropriate test for each exercise, and this script is not in VS Code.
To do this from the classroom terminal, run the following from the build
directory:
cmake_tests ..
make
After making the project, you can run tests from the build
directory with the following command:
../bin/test
Note that the appropriate tests for each exercise will often not compile until the exercise is complete, so if you are seeing compile-time errors with cmake_tests
, check the exercise instructions to ensure that all steps are complete.